package com.alvin.springboot.controller;

import com.alvin.springboot.dao.UserDAOImpl;
import com.alvin.springboot.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: Alvin
 * @Project_name: SpringbootTest
 * @Package_name: com.alvin.springboot.controller
 * @Type_name: UserController
 * @DATE: 2017/5/16
 * @TODO: ${TODO}
 */
@Controller
@RequestMapping(value = "/")
public class UserController {
    @Autowired
    UserDAOImpl userDAOImpl;

    @ResponseBody
    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public void add(HttpServletRequest request,HttpServletResponse response) {
        User user = new User("111","aaaa");
        userDAOImpl.save(user);
        System.out.println("add");
    }

    @ResponseBody
    @RequestMapping(value = "/user", method = RequestMethod.DELETE)
    public void delete(HttpServletRequest request,HttpServletResponse response) {
        userDAOImpl.delete("111");
        System.out.println("delete");
    }

    @ResponseBody
    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public void query(HttpServletRequest request,HttpServletResponse response) {
        userDAOImpl.findById("111");
        System.out.println("query");
    }

    @ResponseBody
    @RequestMapping(value = "/user", method = RequestMethod.PUT)
    public void update(HttpServletRequest request,HttpServletResponse response) {
        User user = new User("111","bbb");
        userDAOImpl.update(user);
        System.out.println("update");
    }
}
